package xyz.zichengdulin.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.zichengdulin.mapper.EmpMapper;
import xyz.zichengdulin.mapper.StudentMapper;
import xyz.zichengdulin.pojo.JobOption;
import xyz.zichengdulin.pojo.StudyOption;
import xyz.zichengdulin.service.ReportService;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 员工职位人数统计
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        //1.调用Mapper接口方法查询数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();   //Map: pos=教研主管，num=1

        //2.封装数据并返回*********重点
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobOption(jobList, dataList);
    }

    /**
     * 员工性别人数统计
     * @return
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /**
     * 学员人数统计
     * @return
     */
    @Override
    public StudyOption getStudentCountData() {
        //1.调用Mapper接口方法查询数据
        List<Map<String, Object>> list = studentMapper.countStudentCountData();   //Map: clz=教研主管，num=1

        //2.封装数据并返回*********重点
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("clz")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new StudyOption(clazzList, dataList);
    }

    /**
     * 统计学员学历信息
     * @return
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }
}
